package dbutils;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * Created by IntelliJ IDEA.
 * User: Admin
 * Date: Jan 19, 2010
 * Time: 11:06:03 PM
 * To change this template use File | Settings | File Templates.
 */
public class StoredQueries {
    public static final String TEST_BODY = "test-body.sql";
    public static final String GROUPS_LIST = "groups-list.sql";
    public static final String SCHEMA_GROUP_ID = "shema-group-id.sql";
    public static final String GROUPS_SELECT = "groups-select.sql";
    public static final String PROBATIONERS_SELECT = "probationers-select.sql";
    public static final String VOLUNTEERS_SELECT = "volunteers-select.sql";
    public static final String CASES_FROM_INFORMATION_SCHEMA = "cases-from-information_schema.sql";
    public static final String VIEW_ANALYS_RESULT = "view-analys-result.sql";
    public static final String STAT_ANALYS = "stat-analys.sql";
    public static final String UNITS_RETRIVE = "units_retrive.sql";
    public static final String ANALYSIS_LIMITS = "analys-limits.sql";
    public static final String VERSION_SELECTION = "version-selection.sql";
    public static final String EXISTS_VERSION_RETRIVE = "exists-version-retrive.sql";
    public static final String CASES_FROM_INFORMATION_TABLE = "cases-from-information_table.sql";
    public static final String ANALYSIS_VERSION = "analysis-version.sql";
    public static final String ANALYSIS_PHASE = "analysis-phase.sql";
    public static final String TRANSLATE_FROM_ADDITIONAL_COLUMNS = "translate-additional_columns.sql";
    public static final String ANALYSIS_PARAMETERS_VERSION = "analysis-parameters-version.sql";
    public static final String GROUPS_IN_SCHEMAS = "groupsinschema.sql";
    public static final String FILL_GROUPS_IN_SCHEMAS = "fill-groups-schema.sql";
    public static final String FIELDS_TRANSLATE = "fields-translate.sql";
    public static final String PROBATIONER_CODE_AND_HOURS="probationer_code_and_hours.sql";

    public static final String QUERY_DIRECTORY = "sql_queries/";

    public static String getQuery(String queryName) {
        try {
            InputStream is = StoredQueries.class.getClassLoader().getResourceAsStream(QUERY_DIRECTORY + queryName);
            BufferedReader reader = new BufferedReader(new InputStreamReader(is));
            StringBuilder query = new StringBuilder();
            String line;

            while ((line = reader.readLine()) != null) {
                query.append(line).append(" ");
            }

            return query.toString();
        }
        catch (Exception e) {
            e.printStackTrace();
            throw new IllegalStateException("No file");
        }
    }
}
